--- 模块功能：注册任务.
-- @author zhangFenghe
-- @module Tweeter.thirdPartyHttpRequest
-- @license MIT
-- @copyright zhangFenghe
-- @release 2025.02.05
module(..., package.seeall) -- 使得文件中的函数在何处都可调用
require "nvm"
require "httpTask"
require "logGenerator"
require "utilsBySelf"

nvm.init("config.lua", true)

local ipThirdCenter = nvm.get("thirdConfig")[11]

--[[
功能  ：注册,变更服务接口-终端通过注册中心进行入网注册，注册成功后，终端获取clientId、uname、pwd等参数，
供应商可以变更scenarioId（安装位置变化时），变更后得到的消息服务参数也随之改变
返回值：Result 具体参数：clientId：客户端Id，预警发布系统唯一ID；uname：账号，用于与MQTT通讯服务；
pwd：密码，用于与MQTT通讯服务。
]]
function RegistrationAndChange(params)
    local registerUrl, cert, body, sign = ipThirdCenter .. "/register/add", nil,
                                          "", ""
    sign = utilsBySelf.NonEmptyParamNameSort(params)
    params.sign = sign
    body = json.encode(params)
    log.info("body:", body)
    httpTask.PostApplicateThird(registerUrl, cert, body, 60000,
                                "registrationAndChangeThird")
end

--[[
功能  ：暂停,恢复服务接口-预警终端通过暂停/恢复来开启或关闭消息接收，
返回值：Result 具体参数：clientId：客户端Id，预警发布系统唯一ID；uname：账号，用于与MQTT通讯服务；
pwd：密码，用于与MQTT通讯服务。
]]
function PauseOrRestore(params)
    local registerUrl, cert, body, sign = ipThirdCenter .. "/register/suspend",
                                          nil, "", ""
    sign = utilsBySelf.NonEmptyParamNameSort(params)
    params.sign = sign
    body = json.encode(params)
    httpTask.PostApplicateThird(registerUrl, cert, body, 60000,
                                "pauseOrRestoreThird")
end

--[[
功能:播控日志接口-预警终端收到预警信息并进行预警、预警倒计时等过程的录屏日志，需在预警结束后回传给地震业务管理平台
参数:
返回值：
]]
function BroadcastControlLog(params)
    local registerUrl, cert, body, sign = ipThirdCenter ..
                                              "/infoback/broadcastlog", nil, {},
                                          ""
    sign = utilsBySelf.NonEmptyParamNameSort(params)
    params.sign = sign
    body = json.encode(params)
    log.info("bodyBroadcastControlLog:", body)
    httpTask.PostApplicateThird(registerUrl, cert, body, 60000,
                                "broadcastControlLog")
end

--[[
功能：预警终端通过MQTT消息接收到的文件ID，通过此接口进行下载压缩文件
]]
function DownloadFills(params)
     local registerUrl, cert, body, sign = ipThirdCenter ..
                                              "/file/download", nil, {},
                                          ""
    sign = utilsBySelf.NonEmptyParamNameSort(params)
    params.sign = sign
    body = json.encode(params)
    httpTask.PostApplicateThird(registerUrl, cert, body, 60000,
                                "downloadFills")
end

--[[
功能：预警终端通过MQTT消息接收到的文件ID，通过此接口进行下载压缩文件
]]
function DownloadFillsKeson(params)
     local registerUrl, cert, body, sign = ipThirdCenter ..
                                              "/file/download", nil, {},
                                          ""
    sign = utilsBySelf.NonEmptyParamNameSort(params)
    params.sign = sign
    log.info("sign:",sign)
    body = json.encode(params)
    local url = "http://118.190.159.110:8080/luding/download/kepu"
    httpTask.PostApplicateThirdKeson(url, cert, body, 60000,
                                "downloadFillsKeson")
end
